const getClassByStaffIdUrl = require('../../../../../config').getClassByStaffIdUrl
const addSignInRecordByQrCode = require('../../../../../config').addSignInRecordByQrCode
const config = require('../../../../../ajax.js');

let app = getApp()
let storageTeacherInfo;
Page({
  data: {
    status:'完成'
  },
  onLoad: function() {
    let that = this;
    wx.getStorage({
      key: 'teacherInfo',
      success: function (res) {
        let organizationId = res.data.organizationId
        let staffId = res.data.staffId

        that.setData({
          organizationId,
          staffId
        })
      }
    })
  },

  // 跳1.人脸识别 2.手动签到
  navScan: function (e){
    let signInType = e.currentTarget.dataset.type
    wx.navigateTo({
      url: './scan?signInType=' + signInType,
    })
  },

	navCode:function(){
    let that = this
		wx.scanCode({
			onlyFromCamera: true,
			success(res) {
        wx.showLoading()

        let codeData = res.result ? res.result : wx.showModal({
          title: '警告',
          content: '二维码无效',
        })

        wx.request({
          url: addSignInRecordByQrCode,
          data: {
            "staffId": that.data.staffId,
            "code": res.result
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          method: 'POST',
          success: function (res) {
            if (res.statusCode == 200){
              wx.showToast({
                title: '签到成功',
                duration: 2000
              })
            }
            else {
              wx.showModal({
                title: '系统提示',
                content: res.data.msg,
              })
            }
          },
          fail: function(res){
            wx.showModal({
              title: '系统提示',
              content: '出错啦，稍后再试',
            })
          },
          complete: function(){
            wx.hideLoading();
          }
        })
			}
		})
	},

  navPickList:function(){
    wx.navigateTo({
      url: '../pickList/pickList',
    })
  }
}) 